export function isPhone(value) {
  return /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/.test(value);
}

/**
 * @description - 校验是否大于规定年龄
 * @param {string} birthday - 出生年月
 * @param {number} num - 规定年龄
 */
export function checkAge(birthday, num) {
  let age;
  const birthdayArr = birthday.split('-');
  const birthdayYear = birthdayArr[0];
  const birthdayMonth = birthdayArr[1];
  const birthdayDay = birthdayArr[2];
  const today = new Date();
  const nowYear = today.getFullYear();
  const nowMonth = today.getMonth() + 1;
  const nowDay = today.getDate();
  if (nowYear === birthdayYear) {
    age = 0; // 同年 则为0岁
  } else {
    const ageDiff = nowYear - birthdayYear; // 年之差
    if (ageDiff > 0) {
      if (nowMonth === birthdayMonth) {
        const dayDiff = nowDay - birthdayDay; // 日之差
        if (dayDiff < 0) {
          age = ageDiff - 1;
        } else {
          age = ageDiff;
        }
      } else {
        const monthDiff = nowMonth - birthdayMonth; // 月之差
        if (monthDiff < 0) {
          age = ageDiff - 1;
        } else {
          age = ageDiff;
        }
      }
    } else {
      age = '未知'; // 返回-1 表示出生日期输入错误 晚于今天
    }
  }

  const bol = age >= num;
  return bol; // 返回周岁年龄
}
